*********************
***** PANEL A *******
* 400% of Federal Poverty Line
*********************
clear all
set more off

*cd "/Users/michaelhotard/Dropbox (IPL)/fee waiver/"
cd "/Users/yasenov/Dropbox (IPL)/fee waiver/"

use "data/usa_00132.dta"
sum age
keep if year >= 2007 & year <= 2016

****************
* demographics
****************
gen byte veteran = vetstat == 2
drop vetstat

gen byte male = sex == 1
drop sex

gen byte married = inlist(marst,1,2)
drop marst

gen byte unempl = empstat == 2
gen byte notinlf = empstat == 3
drop empstat

gen byte medicaid = hinscaid == 2
drop hinscaid

gen byte english = language == 1
drop language

replace incwage = incwage / 1e4

sum inc*
gen byte means_tested = incwelfr > 0 | medicaid == 1 | incsupp > 0  // all these variables are at the individual level. ACS has a food stamp dummy but it is measured at the household level

*gen byte poor = poverty <= 150

* MARRIED TO NATIVE
gen nat = citizen <= 2
gen nat_nokids = nat  // variable indicating whether either spouse is native
replace nat_nokids = 0 if relate > 2 // don't count kids & other non-spouse members as "natives"
egen nat_hshld_head = total(nat_nokids), by(year serial datanum)
replace nat_hshld_head = min(1, nat_hshld_head)
gen byte married_to_citizen = married == 1 & relate <= 2 & nat_hshld_head == 1
drop nat_nokids

replace married = 0 if married_to_citizen == 1   // married means married to a non-citizen

do "code/misc_bpl_recode.do"

gen byte white = race == 1
gen byte black = race == 2
gen byte asian = inlist(race, 4,5,6)

gen agesq = age* age
gen yrsusasq = yrsusa1 * yrsusa1

gen inmetro = metro == 2
recode educ (1 = 3) (2=7) (3=9) (4=10) (5=11) (6=12) (7=13) (8=14) (10=16) (11=18)

****************
* sample selection
****************
keep if age >= 18 & age <= 65

* born in the US
drop if bpl <= 120
tab citizen, sort

drop if citizen == 0 | citizen == 1

* undocumented
drop if bpl == 200 & inlist(citizen, 3,4) & educ <= 12   // Foreign-born Mexicans with high school diploma or less

* students
drop if (age >= 18 & age <= 24) & school == 2
drop school

* non low-income
merge m:1 year famsize using "data/povertyGuidelines.dta", keep(1 3) 
assert _merge == 3
drop _merge

replace ftotinc = . if ftotinc <= 0 | ftotinc == 9999999
keep if ftotinc <= 4 * fpl
* drop if poverty > 300

gen poor = 0
replace poor = 1 if ftotinc <= 1.5 * fpl & statefip != 2 & statefip != 15 // not alaska, hawaii
replace poor = 1 if ftotinc <= 1.5 * fpl_alaska & statefip == 2  //  alaska
replace poor = 1 if ftotinc <= 1.5 * fpl_hawaii & statefip == 15  //  hawaii

replace poverty = ftotinc/fpl if statefip != 2 & statefip != 15   // not alaska, hawaii
replace poverty = ftotinc/fpl_alaska if statefip == 2	// alaska
replace poverty = ftotinc/fpl_hawaii if statefip == 15	// hawaii

* recent immigrants
*keep if yrsusa1 >= 6 | (yrsusa1 >= 4 & married_to_citizen == 1)
keep if yrsusa1 >= 6 | (yrsusa1 >= 4 & married == 1 & nat_hshld_head == 1 & relate <= 2)
*keep if yrsusa1 >= 5 | (yrsusa1 >= 3 & married == 1 & nat_hshld_head == 1 & relate <= 2)
sum yrsusa1

merge m:1 statefip year using "data/local_controls.dta", nogen keep(3)

keep if yrsusa1 <= 40

drop if veteran == 1

************
* treatment
************

gen byte treatment = (poor == 1) | (means_tested == 1)
tab treatment, m

gen byte interaction = treatment * (year >= 2012)
label var interaction "Difference-in-Differences"

xtile poor_tercile = poverty if treatment == 1, nq(3)

***********
* outcome
***********
gen byte y = citizen == 2
tab y

sum
tab year treatment
qui compress

bysort treatment: sum y yrsusa1 poverty age

****************
* regressions
****************	
global controls white black asian male married incwage ///
	unempl notinlf inmetro educ age agesq yrsusasq yrsusa1 ///
	i.year married_to_citizen english unemp lweekly // statefip#c.year
global options absorb(statefip bplgroup) vce(cluster statefip) 


* MAIN
eststo clear
eststo: reghdfe y treatment interaction $controls [pw=perwt], $options
eststo: reghdfe y treatment interaction $controls if year >= 2008 & year <= 2015 [pw=perwt], $options
eststo: reghdfe y treatment interaction $controls if year >= 2009 & year <= 2014 [pw=perwt], $options
eststo: reghdfe y treatment interaction $controls if year >= 2010 & year <= 2013 [pw=perwt], $options

esttab, keep(interaction) ///
	b(%4.3f) se(%4.3f) ///
	mtitles("2007-2016" "2008-2015" "2009-2014" "2010-2013")

esttab using "si/main_rc.tex", keep(interaction) ///
	b(%4.3f) se(%4.3f) ///
	nonum nonotes label ar2 replace star(* .1 ** .05 *** .01) ///
	mtitles("2007-2016" "2008-2015" "2009-2014" "2010-2013") ///
	postfoot("") ///
	prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}\begin{tabular}{l*{4}{c}} \\  &\multicolumn{4}{c}{Panel A: 400$\%$ of Federal Poverty Line}       \\ \cmidrule(lr){2-5}  ")

	
	
	
	
	
	
	
	
	
*********************
***** PANEL B *******
* Controlling for Linear State Trends
*********************
clear all
set more off

*cd "/Users/michaelhotard/Dropbox (IPL)/fee waiver/"
cd "/Users/yasenov/Dropbox (IPL)/fee waiver/"

use "data/usa_00132.dta"
sum age
keep if year >= 2007 & year <= 2016

****************
* demographics
****************
gen byte veteran = vetstat == 2
drop vetstat

gen byte male = sex == 1
drop sex

gen byte married = inlist(marst,1,2)
drop marst

gen byte unempl = empstat == 2
gen byte notinlf = empstat == 3
drop empstat

gen byte medicaid = hinscaid == 2
drop hinscaid

gen byte english = language == 1
drop language

replace incwage = incwage / 1e4

sum inc*
gen byte means_tested = incwelfr > 0 | medicaid == 1 | incsupp > 0  // all these variables are at the individual level. ACS has a food stamp dummy but it is measured at the household level

*gen byte poor = poverty <= 150

* MARRIED TO NATIVE
gen nat = citizen <= 2
gen nat_nokids = nat  // variable indicating whether either spouse is native
replace nat_nokids = 0 if relate > 2 // don't count kids & other non-spouse members as "natives"
egen nat_hshld_head = total(nat_nokids), by(year serial datanum)
replace nat_hshld_head = min(1, nat_hshld_head)
gen byte married_to_citizen = married == 1 & relate <= 2 & nat_hshld_head == 1
drop nat_nokids

replace married = 0 if married_to_citizen == 1   // married means married to a non-citizen

do "code/misc_bpl_recode.do"

gen byte white = race == 1
gen byte black = race == 2
gen byte asian = inlist(race, 4,5,6)

gen agesq = age* age
gen yrsusasq = yrsusa1 * yrsusa1

gen inmetro = metro == 2
recode educ (1 = 3) (2=7) (3=9) (4=10) (5=11) (6=12) (7=13) (8=14) (10=16) (11=18)

****************
* sample selection
****************
keep if age >= 18 & age <= 65

* born in the US
drop if bpl <= 120
tab citizen, sort

drop if citizen == 0 | citizen == 1

* undocumented
drop if bpl == 200 & inlist(citizen, 3,4) & educ <= 12   // Foreign-born Mexicans with high school diploma or less

* students
drop if (age >= 18 & age <= 24) & school == 2
drop school

* non low-income
merge m:1 year famsize using "data/povertyGuidelines.dta", keep(1 3) 
assert _merge == 3
drop _merge

replace ftotinc = . if ftotinc <= 0 | ftotinc == 9999999
keep if ftotinc <= 3 * fpl
* drop if poverty > 300

gen poor = 0
replace poor = 1 if ftotinc <= 1.5 * fpl & statefip != 2 & statefip != 15 // not alaska, hawaii
replace poor = 1 if ftotinc <= 1.5 * fpl_alaska & statefip == 2  //  alaska
replace poor = 1 if ftotinc <= 1.5 * fpl_hawaii & statefip == 15  //  hawaii

replace poverty = ftotinc/fpl if statefip != 2 & statefip != 15   // not alaska, hawaii
replace poverty = ftotinc/fpl_alaska if statefip == 2	// alaska
replace poverty = ftotinc/fpl_hawaii if statefip == 15	// hawaii

* recent immigrants
*keep if yrsusa1 >= 6 | (yrsusa1 >= 4 & married_to_citizen == 1)
keep if yrsusa1 >= 6 | (yrsusa1 >= 4 & married == 1 & nat_hshld_head == 1 & relate <= 2)
*keep if yrsusa1 >= 5 | (yrsusa1 >= 3 & married == 1 & nat_hshld_head == 1 & relate <= 2)
sum yrsusa1

merge m:1 statefip year using "data/local_controls.dta", nogen keep(3)

keep if yrsusa1 <= 40

drop if veteran == 1

************
* treatment
************

gen byte treatment = (poor == 1) | (means_tested == 1)
tab treatment, m

gen byte interaction = treatment * (year >= 2012)
label var interaction "Difference-in-Differences"

xtile poor_tercile = poverty if treatment == 1, nq(3)

***********
* outcome
***********
gen byte y = citizen == 2
tab y

sum
tab year treatment
qui compress

bysort treatment: sum y yrsusa1 poverty age

****************
* regressions
****************	
egen group = group(statefip year)

global controls white black asian male married incwage ///
	unempl notinlf inmetro educ age agesq yrsusasq yrsusa1 ///
	i.year married_to_citizen english unemp lweekly statefip#c.year
global options absorb(statefip bplgroup) vce(cluster group) 


* MAIN
eststo clear
eststo: reghdfe y treatment interaction $controls [pw=perwt], $options
eststo: reghdfe y treatment interaction $controls if year >= 2008 & year <= 2015 [pw=perwt], $options
eststo: reghdfe y treatment interaction $controls if year >= 2009 & year <= 2014 [pw=perwt], $options
eststo: reghdfe y treatment interaction $controls if year >= 2010 & year <= 2013 [pw=perwt], $options

esttab, keep(interaction) ///
	b(%4.3f) se(%4.3f) ///
	mtitles("2007-2016" "2008-2015" "2009-2014" "2010-2013")

esttab using "si/main_rc.tex", keep(interaction) ///
	b(%4.3f) se(%4.3f) ///
	nonum nonotes label ar2 append star(* .1 ** .05 *** .01) ///
	mtitles("2007-2016" "2008-2015" "2009-2014" "2010-2013") ///
	postfoot("") ///
	prehead("\\  &\multicolumn{4}{c}{Panel B: Controlling for Linear State Trends}       \\ \cmidrule(lr){2-5}  ")

	
	
	
	

*********************
***** PANEL C *******
* Residency in the US ≥ 5
*********************
clear all
set more off

*cd "/Users/michaelhotard/Dropbox (IPL)/fee waiver/"
cd "/Users/yasenov/Dropbox (IPL)/fee waiver/"

use "data/usa_00132.dta"
sum age
keep if year >= 2007 & year <= 2016

****************
* demographics
****************
gen byte veteran = vetstat == 2
drop vetstat

gen byte male = sex == 1
drop sex

gen byte married = inlist(marst,1,2)
drop marst

gen byte unempl = empstat == 2
gen byte notinlf = empstat == 3
drop empstat

gen byte medicaid = hinscaid == 2
drop hinscaid

gen byte english = language == 1
drop language

replace incwage = incwage / 1e4

sum inc*
gen byte means_tested = incwelfr > 0 | medicaid == 1 | incsupp > 0  // all these variables are at the individual level. ACS has a food stamp dummy but it is measured at the household level

*gen byte poor = poverty <= 150

* MARRIED TO NATIVE
gen nat = citizen <= 2
gen nat_nokids = nat  // variable indicating whether either spouse is native
replace nat_nokids = 0 if relate > 2 // don't count kids & other non-spouse members as "natives"
egen nat_hshld_head = total(nat_nokids), by(year serial datanum)
replace nat_hshld_head = min(1, nat_hshld_head)
gen byte married_to_citizen = married == 1 & relate <= 2 & nat_hshld_head == 1
drop nat_nokids

replace married = 0 if married_to_citizen == 1   // married means married to a non-citizen

do "code/misc_bpl_recode.do"

gen byte white = race == 1
gen byte black = race == 2
gen byte asian = inlist(race, 4,5,6)

gen agesq = age* age
gen yrsusasq = yrsusa1 * yrsusa1

gen inmetro = metro == 2
recode educ (1 = 3) (2=7) (3=9) (4=10) (5=11) (6=12) (7=13) (8=14) (10=16) (11=18)

****************
* sample selection
****************
keep if age >= 18 & age <= 65

* born in the US
drop if bpl <= 120
tab citizen, sort

drop if citizen == 0 | citizen == 1

* undocumented
drop if bpl == 200 & inlist(citizen, 3,4) & educ <= 12   // Foreign-born Mexicans with high school diploma or less

* students
drop if (age >= 18 & age <= 24) & school == 2
drop school

* non low-income
merge m:1 year famsize using "data/povertyGuidelines.dta", keep(1 3) 
assert _merge == 3
drop _merge

replace ftotinc = . if ftotinc <= 0 | ftotinc == 9999999
keep if ftotinc <= 3 * fpl
* drop if poverty > 300

gen poor = 0
replace poor = 1 if ftotinc <= 1.5 * fpl & statefip != 2 & statefip != 15 // not alaska, hawaii
replace poor = 1 if ftotinc <= 1.5 * fpl_alaska & statefip == 2  //  alaska
replace poor = 1 if ftotinc <= 1.5 * fpl_hawaii & statefip == 15  //  hawaii

replace poverty = ftotinc/fpl if statefip != 2 & statefip != 15   // not alaska, hawaii
replace poverty = ftotinc/fpl_alaska if statefip == 2	// alaska
replace poverty = ftotinc/fpl_hawaii if statefip == 15	// hawaii

* recent immigrants
*keep if yrsusa1 >= 6 | (yrsusa1 >= 4 & married_to_citizen == 1)
*keep if yrsusa1 >= 6 | (yrsusa1 >= 4 & married == 1 & nat_hshld_head == 1 & relate <= 2)
keep if yrsusa1 >= 5 | (yrsusa1 >= 3 & married == 1 & nat_hshld_head == 1 & relate <= 2)
sum yrsusa1

merge m:1 statefip year using "data/local_controls.dta", nogen keep(3)

keep if yrsusa1 <= 40

drop if veteran == 1

************
* treatment
************

gen byte treatment = (poor == 1) | (means_tested == 1)
tab treatment, m

gen byte interaction = treatment * (year >= 2012)
label var interaction "Difference-in-Differences"

xtile poor_tercile = poverty if treatment == 1, nq(3)

***********
* outcome
***********
gen byte y = citizen == 2
tab y

sum
tab year treatment
qui compress

bysort treatment: sum y yrsusa1 poverty age

****************
* regressions
****************	

global controls white black asian male married incwage ///
	unempl notinlf inmetro educ age agesq yrsusasq yrsusa1 ///
	i.year married_to_citizen english unemp lweekly // statefip#c.year
global options absorb(statefip bplgroup) vce(cluster statefip) 


* MAIN
eststo clear
eststo: reghdfe y treatment interaction $controls [pw=perwt], $options
eststo: reghdfe y treatment interaction $controls if year >= 2008 & year <= 2015 [pw=perwt], $options
eststo: reghdfe y treatment interaction $controls if year >= 2009 & year <= 2014 [pw=perwt], $options
eststo: reghdfe y treatment interaction $controls if year >= 2010 & year <= 2013 [pw=perwt], $options

esttab, keep(interaction) ///
	b(%4.3f) se(%4.3f) ///
	mtitles("2007-2016" "2008-2015" "2009-2014" "2010-2013")

esttab using "si/main_rc.tex", keep(interaction) ///
	b(%4.3f) se(%4.3f) ///
	nonum nonotes label ar2 append star(* .1 ** .05 *** .01) ///
	mtitles("2007-2016" "2008-2015" "2009-2014" "2010-2013") ///
	postfoot("") ///
	prehead("\\  &\multicolumn{4}{c}{Panel C: Residency in the US $\geq$ 5}       \\ \cmidrule(lr){2-5}  ")

	
	
	

*********************
***** PANEL D *******
* Including Immigrants from Mexico
*********************
clear all
set more off

*cd "/Users/michaelhotard/Dropbox (IPL)/fee waiver/"
cd "/Users/yasenov/Dropbox (IPL)/fee waiver/"

use "data/usa_00132.dta"
sum age
keep if year >= 2007 & year <= 2016

****************
* demographics
****************
gen byte veteran = vetstat == 2
drop vetstat

gen byte male = sex == 1
drop sex

gen byte married = inlist(marst,1,2)
drop marst

gen byte unempl = empstat == 2
gen byte notinlf = empstat == 3
drop empstat

gen byte medicaid = hinscaid == 2
drop hinscaid

gen byte english = language == 1
drop language

replace incwage = incwage / 1e4

sum inc*
gen byte means_tested = incwelfr > 0 | medicaid == 1 | incsupp > 0  // all these variables are at the individual level. ACS has a food stamp dummy but it is measured at the household level

*gen byte poor = poverty <= 150

* MARRIED TO NATIVE
gen nat = citizen <= 2
gen nat_nokids = nat  // variable indicating whether either spouse is native
replace nat_nokids = 0 if relate > 2 // don't count kids & other non-spouse members as "natives"
egen nat_hshld_head = total(nat_nokids), by(year serial datanum)
replace nat_hshld_head = min(1, nat_hshld_head)
gen byte married_to_citizen = married == 1 & relate <= 2 & nat_hshld_head == 1
drop nat_nokids

replace married = 0 if married_to_citizen == 1   // married means married to a non-citizen

do "code/misc_bpl_recode.do"

gen byte white = race == 1
gen byte black = race == 2
gen byte asian = inlist(race, 4,5,6)

gen agesq = age* age
gen yrsusasq = yrsusa1 * yrsusa1

gen inmetro = metro == 2
recode educ (1 = 3) (2=7) (3=9) (4=10) (5=11) (6=12) (7=13) (8=14) (10=16) (11=18)

****************
* sample selection
****************
keep if age >= 18 & age <= 65

* born in the US
drop if bpl <= 120
tab citizen, sort

drop if citizen == 0 | citizen == 1

* undocumented
*drop if bpl == 200 & inlist(citizen, 3,4) & educ <= 12   // Foreign-born Mexicans with high school diploma or less

* students
drop if (age >= 18 & age <= 24) & school == 2
drop school

* non low-income
merge m:1 year famsize using "data/povertyGuidelines.dta", keep(1 3) 
assert _merge == 3
drop _merge

replace ftotinc = . if ftotinc <= 0 | ftotinc == 9999999
keep if ftotinc <= 3 * fpl
* drop if poverty > 300

gen poor = 0
replace poor = 1 if ftotinc <= 1.5 * fpl & statefip != 2 & statefip != 15 // not alaska, hawaii
replace poor = 1 if ftotinc <= 1.5 * fpl_alaska & statefip == 2  //  alaska
replace poor = 1 if ftotinc <= 1.5 * fpl_hawaii & statefip == 15  //  hawaii

replace poverty = ftotinc/fpl if statefip != 2 & statefip != 15   // not alaska, hawaii
replace poverty = ftotinc/fpl_alaska if statefip == 2	// alaska
replace poverty = ftotinc/fpl_hawaii if statefip == 15	// hawaii

* recent immigrants
keep if yrsusa1 >= 6 | (yrsusa1 >= 4 & married == 1 & nat_hshld_head == 1 & relate <= 2)
*keep if yrsusa1 >= 5 | (yrsusa1 >= 3 & married == 1 & nat_hshld_head == 1 & relate <= 2)
sum yrsusa1

merge m:1 statefip year using "data/local_controls.dta", nogen keep(3)

keep if yrsusa1 <= 40

drop if veteran == 1

************
* treatment
************

gen byte treatment = (poor == 1) | (means_tested == 1)
tab treatment, m

gen byte interaction = treatment * (year >= 2012)
label var interaction "Difference-in-Differences"

xtile poor_tercile = poverty if treatment == 1, nq(3)

***********
* outcome
***********
gen byte y = citizen == 2
tab y

sum
tab year treatment
qui compress

bysort treatment: sum y yrsusa1 poverty age

****************
* regressions
****************	

global controls white black asian male married incwage ///
	unempl notinlf inmetro educ age agesq yrsusasq yrsusa1 ///
	i.year married_to_citizen english unemp lweekly // statefip#c.year
global options absorb(statefip bplgroup) vce(cluster statefip) 


* MAIN
eststo clear
eststo: reghdfe y treatment interaction $controls [pw=perwt], $options
eststo: reghdfe y treatment interaction $controls if year >= 2008 & year <= 2015 [pw=perwt], $options
eststo: reghdfe y treatment interaction $controls if year >= 2009 & year <= 2014 [pw=perwt], $options
eststo: reghdfe y treatment interaction $controls if year >= 2010 & year <= 2013 [pw=perwt], $options

esttab, keep(interaction) ///
	b(%4.3f) se(%4.3f) ///
	mtitles("2007-2016" "2008-2015" "2009-2014" "2010-2013")

esttab using "si/main_rc.tex", keep(interaction) ///
	b(%4.3f) se(%4.3f) ///
	nonum nonotes label ar2 append star(* .1 ** .05 *** .01) ///
	mtitles("2007-2016" "2008-2015" "2009-2014" "2010-2013") ///
	postfoot("") ///
	prehead("\\  &\multicolumn{4}{c}{Panel D: Including Low-Skill Immigrants from Mexico}       \\ \cmidrule(lr){2-5}  ")


	
	
	
	
	
	

*********************
***** PANEL E *******
* Fee Waiver Introduced in 2011
*********************
clear all
set more off

*cd "/Users/michaelhotard/Dropbox (IPL)/fee waiver/"
cd "/Users/yasenov/Dropbox (IPL)/fee waiver/"

use "data/usa_00132.dta"
sum age
keep if year >= 2007 & year <= 2016

****************
* demographics
****************
gen byte veteran = vetstat == 2
drop vetstat

gen byte male = sex == 1
drop sex

gen byte married = inlist(marst,1,2)
drop marst

gen byte unempl = empstat == 2
gen byte notinlf = empstat == 3
drop empstat

gen byte medicaid = hinscaid == 2
drop hinscaid

gen byte english = language == 1
drop language

replace incwage = incwage / 1e4

sum inc*
gen byte means_tested = incwelfr > 0 | medicaid == 1 | incsupp > 0  // all these variables are at the individual level. ACS has a food stamp dummy but it is measured at the household level

*gen byte poor = poverty <= 150

* MARRIED TO NATIVE
gen nat = citizen <= 2
gen nat_nokids = nat  // variable indicating whether either spouse is native
replace nat_nokids = 0 if relate > 2 // don't count kids & other non-spouse members as "natives"
egen nat_hshld_head = total(nat_nokids), by(year serial datanum)
replace nat_hshld_head = min(1, nat_hshld_head)
gen byte married_to_citizen = married == 1 & relate <= 2 & nat_hshld_head == 1
drop nat_nokids

replace married = 0 if married_to_citizen == 1   // married means married to a non-citizen

do "code/misc_bpl_recode.do"

gen byte white = race == 1
gen byte black = race == 2
gen byte asian = inlist(race, 4,5,6)

gen agesq = age* age
gen yrsusasq = yrsusa1 * yrsusa1

gen inmetro = metro == 2
recode educ (1 = 3) (2=7) (3=9) (4=10) (5=11) (6=12) (7=13) (8=14) (10=16) (11=18)

****************
* sample selection
****************
keep if age >= 18 & age <= 65

* born in the US
drop if bpl <= 120
tab citizen, sort

drop if citizen == 0 | citizen == 1

* undocumented
drop if bpl == 200 & inlist(citizen, 3,4) & educ <= 12   // Foreign-born Mexicans with high school diploma or less

* students
drop if (age >= 18 & age <= 24) & school == 2
drop school

* non low-income
merge m:1 year famsize using "data/povertyGuidelines.dta", keep(1 3) 
assert _merge == 3
drop _merge

replace ftotinc = . if ftotinc <= 0 | ftotinc == 9999999
keep if ftotinc <= 3 * fpl
* drop if poverty > 300

gen poor = 0
replace poor = 1 if ftotinc <= 1.5 * fpl & statefip != 2 & statefip != 15 // not alaska, hawaii
replace poor = 1 if ftotinc <= 1.5 * fpl_alaska & statefip == 2  //  alaska
replace poor = 1 if ftotinc <= 1.5 * fpl_hawaii & statefip == 15  //  hawaii

replace poverty = ftotinc/fpl if statefip != 2 & statefip != 15   // not alaska, hawaii
replace poverty = ftotinc/fpl_alaska if statefip == 2	// alaska
replace poverty = ftotinc/fpl_hawaii if statefip == 15	// hawaii

* recent immigrants
keep if yrsusa1 >= 6 | (yrsusa1 >= 4 & married == 1 & nat_hshld_head == 1 & relate <= 2)
*keep if yrsusa1 >= 5 | (yrsusa1 >= 3 & married == 1 & nat_hshld_head == 1 & relate <= 2)
sum yrsusa1

merge m:1 statefip year using "data/local_controls.dta", nogen keep(3)

keep if yrsusa1 <= 40

drop if veteran == 1

************
* treatment
************

gen byte treatment = (poor == 1) | (means_tested == 1)
tab treatment, m

gen byte interaction = treatment * (year >= 2011)
label var interaction "Difference-in-Differences"

xtile poor_tercile = poverty if treatment == 1, nq(3)

***********
* outcome
***********
gen byte y = citizen == 2
tab y

sum
tab year treatment
qui compress

bysort treatment: sum y yrsusa1 poverty age

****************
* regressions
****************	

global controls white black asian male married incwage ///
	unempl notinlf inmetro educ age agesq yrsusasq yrsusa1 ///
	i.year married_to_citizen english unemp lweekly // statefip#c.year
global options absorb(statefip bplgroup) vce(cluster statefip) 


* MAIN
eststo clear
eststo: reghdfe y treatment interaction $controls [pw=perwt], $options
eststo: reghdfe y treatment interaction $controls if year >= 2008 & year <= 2015 [pw=perwt], $options
eststo: reghdfe y treatment interaction $controls if year >= 2009 & year <= 2014 [pw=perwt], $options
eststo: reghdfe y treatment interaction $controls if year >= 2010 & year <= 2013 [pw=perwt], $options

esttab, keep(interaction) ///
	b(%4.3f) se(%4.3f) ///
	mtitles("2007-2016" "2008-2015" "2009-2014" "2010-2013")

esttab using "si/main_rc.tex", keep(interaction) ///
	b(%4.3f) se(%4.3f) ///
	nonum nonotes label ar2 append star(* .1 ** .05 *** .01) ///
	mtitles("2007-2016" "2008-2015" "2009-2014" "2010-2013") ///
	postfoot("") ///
	prehead("\\  &\multicolumn{4}{c}{Panel E: Fee Waiver Introduced in 2011}       \\ \cmidrule(lr){2-5}  ")

	
	
	
	
	
	

*********************
***** PANEL F *******
* Controlling for IPUMS Citizenship Imputation Flag
*********************
clear all
set more off

*cd "/Users/michaelhotard/Dropbox (IPL)/fee waiver/"
cd "/Users/yasenov/Dropbox (IPL)/fee waiver/"

use "data/usa_00132.dta"
sum age
keep if year >= 2007 & year <= 2016

****************
* demographics
****************
gen byte veteran = vetstat == 2
drop vetstat

gen byte male = sex == 1
drop sex

gen byte married = inlist(marst,1,2)
drop marst

gen byte unempl = empstat == 2
gen byte notinlf = empstat == 3
drop empstat

gen byte medicaid = hinscaid == 2
drop hinscaid

gen byte english = language == 1
drop language

replace incwage = incwage / 1e4

sum inc*
gen byte means_tested = incwelfr > 0 | medicaid == 1 | incsupp > 0  // all these variables are at the individual level. ACS has a food stamp dummy but it is measured at the household level

*gen byte poor = poverty <= 150

* MARRIED TO NATIVE
gen nat = citizen <= 2
gen nat_nokids = nat  // variable indicating whether either spouse is native
replace nat_nokids = 0 if relate > 2 // don't count kids & other non-spouse members as "natives"
egen nat_hshld_head = total(nat_nokids), by(year serial datanum)
replace nat_hshld_head = min(1, nat_hshld_head)
gen byte married_to_citizen = married == 1 & relate <= 2 & nat_hshld_head == 1
drop nat_nokids

replace married = 0 if married_to_citizen == 1   // married means married to a non-citizen

do "code/misc_bpl_recode.do"

gen byte white = race == 1
gen byte black = race == 2
gen byte asian = inlist(race, 4,5,6)

gen agesq = age* age
gen yrsusasq = yrsusa1 * yrsusa1

gen inmetro = metro == 2
recode educ (1 = 3) (2=7) (3=9) (4=10) (5=11) (6=12) (7=13) (8=14) (10=16) (11=18)

****************
* sample selection
****************
keep if age >= 18 & age <= 65

* born in the US
drop if bpl <= 120
tab citizen, sort

drop if citizen == 0 | citizen == 1

* undocumented
drop if bpl == 200 & inlist(citizen, 3,4) & educ <= 12   // Foreign-born Mexicans with high school diploma or less

* students
drop if (age >= 18 & age <= 24) & school == 2
drop school

* non low-income
merge m:1 year famsize using "data/povertyGuidelines.dta", keep(1 3) 
assert _merge == 3
drop _merge

replace ftotinc = . if ftotinc <= 0 | ftotinc == 9999999
keep if ftotinc <= 3 * fpl
* drop if poverty > 300

gen poor = 0
replace poor = 1 if ftotinc <= 1.5 * fpl & statefip != 2 & statefip != 15 // not alaska, hawaii
replace poor = 1 if ftotinc <= 1.5 * fpl_alaska & statefip == 2  //  alaska
replace poor = 1 if ftotinc <= 1.5 * fpl_hawaii & statefip == 15  //  hawaii

replace poverty = ftotinc/fpl if statefip != 2 & statefip != 15   // not alaska, hawaii
replace poverty = ftotinc/fpl_alaska if statefip == 2	// alaska
replace poverty = ftotinc/fpl_hawaii if statefip == 15	// hawaii

* recent immigrants
keep if yrsusa1 >= 6 | (yrsusa1 >= 4 & married == 1 & nat_hshld_head == 1 & relate <= 2)
*keep if yrsusa1 >= 5 | (yrsusa1 >= 3 & married == 1 & nat_hshld_head == 1 & relate <= 2)
sum yrsusa1

merge m:1 statefip year using "data/local_controls.dta", nogen keep(3)

keep if yrsusa1 <= 40

drop if veteran == 1

************
* treatment
************

gen byte treatment = (poor == 1) | (means_tested == 1)
tab treatment, m

gen byte interaction = treatment * (year >= 2012)
label var interaction "Difference-in-Differences"

xtile poor_tercile = poverty if treatment == 1, nq(3)

***********
* outcome
***********
gen byte y = citizen == 2
tab y

sum
tab year treatment
qui compress

bysort treatment: sum y yrsusa1 poverty age

****************
* regressions
****************	

global controls white black asian male married incwage ///
	unempl notinlf inmetro educ age agesq yrsusasq yrsusa1 ///
	i.year married_to_citizen english unemp lweekly  i.qcitizen // statefip#c.year
global options absorb(statefip bplgroup) vce(cluster statefip) 


* MAIN
eststo clear
eststo: reghdfe y treatment interaction $controls [pw=perwt], $options
eststo: reghdfe y treatment interaction $controls if year >= 2008 & year <= 2015 [pw=perwt], $options
eststo: reghdfe y treatment interaction $controls if year >= 2009 & year <= 2014 [pw=perwt], $options
eststo: reghdfe y treatment interaction $controls if year >= 2010 & year <= 2013 [pw=perwt], $options

esttab, keep(interaction) ///
	b(%4.3f) se(%4.3f) ///
	mtitles("2007-2016" "2008-2015" "2009-2014" "2010-2013")

esttab using "si/main_rc.tex", keep(interaction) ///
	b(%4.3f) se(%4.3f) ///
	nonum nonotes label ar2 append star(* .1 ** .05 *** .01) ///
	mtitles("2007-2016" "2008-2015" "2009-2014" "2010-2013") ///
	prehead("\\  &\multicolumn{4}{c}{Panel F: Controlling for IPUMS Citizenship Imputation Flag}       \\ \cmidrule(lr){2-5}  ")
	
